package top.chengdongqing.mishop.user.address

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import top.chengdongqing.mishop.entities.UserAddress
import java.io.Serializable

data class ShippingAddressDTO(
    val id: Int?,
    val recipientName: String,
    val recipientPhone: String,
    val city: List<CityItem>,
    val address: String,
    val label: String?
) : Serializable {
    companion object {
        fun of(address: UserAddress): ShippingAddressDTO {
            return ShippingAddressDTO(
                address.id,
                address.recipientName,
                address.recipientPhone,
                jacksonObjectMapper().readValue(address.city),
                address.address,
                address.label
            )
        }
    }
}

data class CityItem(
    val name: String,
    val code: String
) : Serializable